function [h7,G,max_l,max_alpha]=channel_acc2(h,M1,N1,flag)
%% 分辨率
    fb_tao=3/16000;  %s
    fb_t=510*4/16000/512;  %s
    doppler_per_tap=1/(16*0.1);
%% 采样率变换
if flag==1
    rate=2;
    % name="NOF1";
else
    rate=2;
    % name="NCS1";
end

%计算最大多普勒频移（使用原始信道）

    % h8=fftshift(fft(h),1);
    % h9=h8.*conj(h8);
    % hlog2=h9;
    % hlog2(abs(hlog2)<rate*2*mean(mean(abs(hlog2))))=0;
    % v=sum(hlog2,2);
    % max_v=0;
    % for ff = size(v,1)/2:-1: 1
    %     if abs(v(ff))==0
    %         max_v=ff-size(v,1)/2;
    %         break;
    %     end
    % end
    % max_alpha=abs(max_v)*(1/fb_t/size(h,1))/doppler_per_tap;


    %降采样
    h2=h(:,1:3:end);
    %升采样
    h3=h2(1:17,:);
   

    %复制法
%     h4=repmat(h3(1,:),512,1);
%     for i = 2:size(h3,1)
%         h4=[h4;repmat(h2(i,:),512,1)];
%     end
% 插值法
    xx=1:1/512:17-1/512;
    h4=interp1(1:17,h3,xx,'spline');

    h5=h4/max(max(abs(h4)));
    h6=h5;
    h6(abs(h6)<rate*mean(mean(abs(h6))))=0;
% 

    
% %%  画信道图

%     Fn = dftmtx(N);       % Generate the DFT matrix
%     Fn = Fn./norm(Fn);    % normalize the DFT matrix
% 
    % Fm = dftmtx(M);       % Generate the DFT matrix
    % Fm = Fm./norm(Fm);    % normalize the DFT matrix
%     [M,N]=size(h6);
% 
% 
    % t=(0:(M-1))*fb_t;  
    % doppler=-1/fb_t/2:1/fb_t/(M-1):1/fb_t/2;
    % tao=(0:(N-1))*fb_tao;
    % freqence=-1/fb_tao/2:1/fb_tao/(N-1):1/fb_tao/2;
% % 时间-时延
% % 时间
% % |
% % |
% % |-------->时延
% 
%     hlog=20*log10(abs(h6));
%     set(figure,'visible','on');
%     figure(1)
%     pcolor(tao*1000,t,hlog);
%     mesh(0:fb_tao:85*fb_tao,0:fb_t:8191*fb_t,hlog);
    % colormap(turbo);
    % shading interp;
    % tao_min=min(tao*1000);tao_max=max(tao*1000);%ms
    % t_min=min(t);t_max=max(t);
    % c_min=-40; c_max=0;clim([c_min c_max]);
    % axis([tao_min,tao_max,t_min,t_max]);   
%     xlabel( 'delay (ms)','FontName','Times New Roman','FontSize',12 );
%     ylabel( 'Time(s)','FontName','Times New Roman','FontSize',12 );
%     title('Time evolution (dB)','FontName','Times New Roman','FontSize',12 );
% % 时间-频率
% % 时间
% % |
% % |
% % |-------->频率
%     h7=fftshift(h6*Fn,2);
%     hlog=20*log10(abs(h7));
%     set(figure,'visible','on');
%     figure(2);
% %   pcolor(0:1/fb_tao/85:1/fb_tao,0:fb_t:8191*fb_t,hlog);
%     mesh(freqence,t,hlog);
%     colormap(turbo);
%     shading interp;
%     xlabel( 'frequence (Hz)','FontName','Times New Roman','FontSize',12 );
%     ylabel( 'Time(s)','FontName','Times New Roman','FontSize',12 );
%     title('Time evolution (dB)','FontName','Times New Roman','FontSize',12 );
% 
%     % 多普勒-时延
% % 多普勒
% % |
% % |
% % |-------->时延
% 
    % h8=fftshift(Fm*h6,1);
%     h8=fftshift(fft(h6),1);
%     h9=h8.*conj(h8);
%     hlog=10*log10(h9./max(max(h9)));
% 
%     set(figure,'visible','on');
%     figure(3)
%     pcolor(tao*1000,doppler,hlog);
% %   mesh(0:fb_tao:85*fb_tao,0:1/fb_t/8191:1/fb_t,hlog);;
%     colormap(turbo);
%     shading interp;
%     c_min=-40; c_max=0;clim([c_min c_max]);%colormap( hot );
%     tao_min=min(tao*1000);tao_max=max(tao*1000);t_min=min(doppler);t_max=max(doppler);
%     axis([tao_min,tao_max,t_min,t_max]);
%     xlabel( 'delay (ms)','FontName','Times New Roman','FontSize',12 );
%     ylabel( 'Doppler(Hz)','FontName','Times New Roman','FontSize',12 );
%     title('Time evolution (dB)','FontName','Times New Roman','FontSize',12 );


   %%  计算G矩阵
    h7=h6.';
    max_l = 0;
    %计算最大时延
    tao=sum(h7,2);
    for ff = size(tao,1):-1:1
        if abs(tao(ff))~=0
            max_l=ff;
            break;
        end
    end

    h8=h7(1:max_l,:);
    G=zeros(N1*M1,N1*M1);
    for q=0:N1*M1-1
        for l=1:max_l
            if(mod(q,M1)>=l) % ZP
                G(q+1,q+1-l)=h8(l,q+1);                     % 42
            end
        end
    end

    %计算最大多普勒
    h9=fftshift(fft(h6),1);
    h10=h9.*conj(h9);
    % hlog=10*log10(h10./max(max(h10)));
    hlog2=h10;
    hlog2(abs(hlog2)<rate*mean(mean(abs(hlog2))))=0;
    v=sum(hlog2,2);
    max_v=0;
    for ff = size(v,1)/2:-1: 1
        if abs(v(ff))==0
            max_v=ff-size(v,1)/2;
            break;
        end
    end
    max_alpha=abs(max_v)*(1/fb_t/size(h6,1))/doppler_per_tap;


    



    
end
